﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataRepositoryLayer.Interfaces;
using ModelLayer;
using System.Runtime.Serialization;

namespace DataRepositoryLayer.Classes
{
    public class StationRepository : GenericDataRepository<Station>, IStationRepository
    {
        public StationRepository(IUnitOfWork unitOfWork)
            : base(unitOfWork)
        {

        }

        public IList<Station> GetAllForGraph()
        {
            return base.GetAll(sp => sp.Pricings, sb => sb.Batteries.Select(b => b.BatteryReservations)); 
            // Remember that you can do sth like this to nest includes  a => a.Pricings.Select(b => b.BatteryType)
        }


        public IList<Station> GetRouteStations(IList<Station> desiredStations)
        {
            int[] stationIds = new int[desiredStations.Count];
            int length = desiredStations.Count;
            for (int i = 0; i < length; i++)
            {
                stationIds[i] = desiredStations[i].id;
            }
            return GetList(s => stationIds.Contains(s.id), bat => bat.Batteries);
        }

        public IList<Station> GetAllStationsForManagementSystem()
        {
            return GetAll(s => s.Batteries);
        }

        public Station GetByIdWithBatteries(int id)
        {
            return GetSingle(s => s.id == id, st => st.Batteries);
        }



    }
}
